﻿using Registro.Compras.Data.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Registro.Compras.Data.Mappings
{
    public class ReferenciaComprobanteMap : EntityTypeConfiguration<ReferenciaComprobante>
    {
        public ReferenciaComprobanteMap()
        {
            //table
            ToTable("ReferenciaComprobantes");

            //pk
            HasKey(t => t.Id);

            //property
            Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(t => t.Fecha).IsRequired();
            Property(t => t.Tabla10Id).IsRequired();
            Property(t => t.Serie).IsRequired();
            Property(t => t.N_Comprobante).IsRequired();
            Property(t => t.Base1Id).IsOptional();

            //relationship
            HasRequired(t => t.Tabla10).WithMany(c => c.ReferenciaComprobantes).HasForeignKey(t => t.Tabla10Id).WillCascadeOnDelete(false);
            HasOptional(t => t.Base1).WithMany(c => c.ReferenciaComprobantes).HasForeignKey(t => t.Base1Id).WillCascadeOnDelete(false);
        }
    }
}
